// 生产环境，测试和正式
const IS_PROD = ['production'].includes(process.env.NODE_ENV);
const devServerPort = 8081;
console.log(process.env.VUE_APP_BASE_API);
const TransformPages = require('uni-read-pages');
const { webpack } = new TransformPages();
const path = require('path');

module.exports = {
  lintOnSave: !IS_PROD,
  productionSourceMap: false,

  devServer: {
    port: devServerPort,
    open: false,
    overlay: {
      warnings: false,
      errors: true,
    },
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: process.env.VUE_APP_BASE_HOST + process.env.VUE_APP_BASE_API, // 后端接口测试环境地址  配nginx 时使用
        changeOrigin: true, // 是否允许跨越
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: '',
        },
      },
    },
  },
  css: {
    loaderOptions: {
      sass: {
        implementation: require('sass'),
        prependData: '@import "./tempui/index.scss";',
        sassOptions: {
          fiber: false,
          outputStyle: 'expanded',
          includePaths: [path.resolve(__dirname, 'tempui')]
        }
      }
    }
  },
  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        ROUTES: webpack.DefinePlugin.runtimeValue(() => {
          const tfPages = new TransformPages({
            includes: ['path', 'name', 'aliasPath', 'meta'],
          });
          return JSON.stringify(tfPages.routes);
        }, true),
      }),
    ],
    resolve: {
      alias: {
        'styles': path.resolve(__dirname, './tempui'),
        '@': path.resolve(__dirname, './src')
      }
    }
  },
};
